
import { Decimal } from 'decimal.js'

import Vue from 'vue'

Decimal.set({
    precision: 300,
    rounding: 4, // 不能改
    toExpNeg: -7, // 科学计数法,-7位
    toExpPos: 21, // 科学计数法,21位
    maxE: 300, // 正指数值极限，超过该极限值会发生 Infinity 溢出。 JavaScript 对于 308 以上的指数会溢出至 Infinity 无穷大.
    minE: -500 ,
})

// 加
function bigNumAdd(a, b) {
    let res = new Decimal(a).plus(new Decimal(b))
    return res
}

// 减
function bigNumLessen(a, b) {
    let res = new Decimal(a).sub(new Decimal(b))
    return res
}

// 乘
function bigNumMultip(a, b, len = 2) {
    const num1 = new Decimal(a);
    const num2 = new Decimal(b);
    // 进行乘法运算
    const result = num1.times(num2);
    // 将结果转换为字符串
    const resultStr = result.toFixed(len);
    return resultStr;
}

// 除
function bigNumDivision(a, b) {

    let res = new Decimal(a).div(b)
    return res;
}


function bigNumFixed(num, len = 2) { // 0
    const res = new Decimal(num).toFixed(len)
    return res
}

function bigNumcomparedTo(a, b) {
    const res = new Decimal(a).comparedTo(new Decimal(b))
    return res === 1
}
function bigNumAbsoluteComparedTo(a, b) {
    const res = new Decimal(a).absoluteValue().comparedTo(new Decimal(b).absoluteValue())
    return res === 1
}




































function bigNumDivisionPrec(num, len) { // 0
    const x = new Decimal(num)
    let res = x.prec(len)
    return res
}


Vue.prototype.bigNumAdd = bigNumAdd
Vue.prototype.bigNumLessen = bigNumLessen
Vue.prototype.bigNumMultip = bigNumMultip
Vue.prototype.bigNumDivision = bigNumDivision
Vue.prototype.bigNumFixed = bigNumFixed
Vue.prototype.bigNumcomparedTo = bigNumcomparedTo
Vue.prototype.bigNumAbsoluteComparedTo = bigNumAbsoluteComparedTo
// Vue.prototype.precCustom1 = precCustom1
